import request from '@/utils/request'

// 获取所有预约记录
export function getAllAppointments() {
  return request({
    url: '/api/appointments',
    method: 'get'
  })
}

// 根据ID获取预约记录
export function getAppointmentById(appointmentId) {
  return request({
    url: `/api/appointments/${appointmentId}`,
    method: 'get'
  })
}

// 根据用户ID获取预约记录
export function getAppointmentsByUserId(userId) {
  return request({
    url: `/api/appointments/user/${userId}`,
    method: 'get'
  })
}

// 根据车辆ID获取预约记录
export function getAppointmentsByCarId(carId) {
  return request({
    url: `/api/appointments/car/${carId}`,
    method: 'get'
  })
}

// 根据经销商ID获取预约记录
export function getAppointmentsByDealerId(dealerId) {
  return request({
    url: `/api/appointments/dealer/${dealerId}`,
    method: 'get'
  })
}

// 根据状态获取预约记录
export function getAppointmentsByStatus(status) {
  return request({
    url: `/api/appointments/status/${status}`,
    method: 'get'
  })
}

// 添加预约记录
export function addAppointment(data) {
  return request({
    url: '/api/appointments',
    method: 'post',
    data
  })
}

// 更新预约记录
export function updateAppointment(data) {
  return request({
    url: '/api/appointments',
    method: 'put',
    data
  })
}

// 删除预约记录
export function deleteAppointment(appointmentId) {
  return request({
    url: `/api/appointments/${appointmentId}`,
    method: 'delete'
  })
}

// 批量删除预约记录
export function batchDeleteAppointments(ids) {
  const idArray = ids.split(',');
  const promises = idArray.map(id => deleteAppointment(id));
  
  return Promise.all(promises).then(() => {
    return {
      code: 200,
      message: 'success',
      data: null
    }
  });
}

// 条件查询预约记录
export function searchAppointments(data) {
  return request({
    url: '/api/appointments/search',
    method: 'post',
    data
  })
}

// 更新预约状态
export function updateAppointmentStatus(appointmentId, status) {
  return request({
    url: `/api/appointments/${appointmentId}/status/${status}`,
    method: 'put'
  })
} 